﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Scriptor.Presentation.Entity;

namespace Scriptor.Presentation.Templates
{
    public class ServiceImplementationTemplate
    {
        List<string> gUsing { get; set; }
        public StringBuilder clausulaUsingFormatada { get; set; }

        List<string> gImplementation { get; set; }
        public StringBuilder clausulaImplementationFormatada { get; set; }

        List<string> gMethod { get; set; }
        public StringBuilder methodImplementationFormatado { get; set; }

        public string strUsing()
        {
            gUsing = new List<string>();

            gUsing.Add("using System.ServiceModel;");
            gUsing.Add("using Sinacor.Servico.Bmf.Agente.Service.ServiceContract;");
            gUsing.Add("using Sinacor.Infra.Service.Security.Services;");
            gUsing.Add("using System.Collections.Generic;");
            
            clausulaUsingFormatada = new StringBuilder();

            foreach (string str in gUsing)
            {
                clausulaUsingFormatada.Append(str);
                clausulaUsingFormatada.Append(Environment.NewLine);
            }

            return clausulaUsingFormatada.ToString();
        }

        public string strImplementation(string pNameSpace, string pClassName,bool showDecorators, bool showInheritingOnImplementation)
        {
            gImplementation = new List<string>();

            gImplementation.Add("namespace " + pNameSpace);
            gImplementation.Add("{");

            if (showDecorators)
            {
                gImplementation.Add("\t[SinacorServiceBehavior]");
            }

            if (showInheritingOnImplementation)
            {
                gImplementation.Add("\tpublic class " + pClassName + " : " + "I" + pClassName);
            }
            else
            {
                gImplementation.Add("\tpublic class " + pClassName);
            }

            gImplementation.Add("\t{");
            gImplementation.Add("@@class-body");
            gImplementation.Add("\t}");
            gImplementation.Add("}");

            clausulaImplementationFormatada = new StringBuilder();

            foreach (string str in gImplementation)
            {
                clausulaImplementationFormatada.Append(str);
                clausulaImplementationFormatada.Append(Environment.NewLine);
            }

            return clausulaImplementationFormatada.ToString();
        }

        public string strMethod(Method mtd)
        {
            gMethod = new List<string>();
            //Adicionado: 21/8
            if (mtd.MethodComent.Trim().Length > 0)
            {
                gMethod.Add("\t\t/// <summary>");
                gMethod.Add("\t\t///" + mtd.MethodComent.Replace("\n", "\n\t\t///"));
                gMethod.Add("\t\t/// </summary>");
            }
            //Fim Adicionado. phsilva
            gMethod.Add("\t\t" + "public " + mtd.MethodSignature);
            gMethod.Add("\t\t" + "{");
            gMethod.Add("\t\t" + "}");
            
            methodImplementationFormatado = new StringBuilder();

            foreach (string str in gMethod)
            {
                methodImplementationFormatado.Append(str);
                methodImplementationFormatado.Append(Environment.NewLine);
            }
            
            methodImplementationFormatado.Append(Environment.NewLine);

            return methodImplementationFormatado.ToString();
        }

        public string AppendMethod(string pClassScope, StringBuilder stb)
        {
            return pClassScope.ToString().Replace("@@class-body", stb.ToString());
        }
    }
}
